package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DeviceController
 * @Author chendongping
 * @Date 2025-05-19  18:26
 */
@RestController
@RequestMapping("/iot")
public class DeviceController extends BaseController{

    @Autowired
    private DeviceService deviceService;
    /**
     * 获取所有设备数据
     */
    @PostMapping("/syncProductList")
    public ResponseResult getAllDeviceData() {
        deviceService.getAllDeviceData();
        return success();
    }

    /**
     * 查询所有设备数据
     */
    @GetMapping("/allProduct")
    @ApiOperation(value = "查询所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        return ResponseResult.success(deviceService.allProduct());
    }

    /**
     * 注册设备
     */

    @PostMapping("/RegisterDevice")
    public ResponseResult addDevice(@RequestBody DeviceDto deviceDto){
        deviceService.addDevice(deviceDto);
        return success();
    }

    /**
     * 分页查询设备
     */

    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto ){
       PageResponse<DeviceVo> deviceVoPageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return success(deviceVoPageResponse);
    }

    /**
     *查询设备详细数据
     */
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> getDeviceDetail(@RequestBody QueryDeviceDetailRequest queryDeviceDetailRequest){
        return ResponseResult.success(deviceService.queryDeviceDetail(queryDeviceDetailRequest));
    }

    /**
     *查看指定产品的已发布物模型中的功能定义详情
     */
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<QueryThingModelResponseBody.QueryThingModelResponseBodyData> queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request){
        return deviceService.queryThingModelPublished(request);
    }

    /**
     *查询指定设备的物模型运行状态
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return deviceService.queryDevicePropertyStatus(request);
    }

    /**
     * 修改设备
     */
    @PostMapping("/UpdateDevice")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return success();
    }
    /**
     * 删除设备
     */
    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceRequest request){
        deviceService.deleteDevice(request);
        return success();
    }
}

